﻿#region 命名空间

using System;
using System.Web.UI.WebControls;
using WinnerCMS.BLL;
using WinnerCMS.Common;
using WinnerCMS.Model;
using WinnerCMS.Model.Attribute;

#endregion

namespace WinnerCMS.WebUI.Admin.Common
{
    /// <summary>
    ///     通用评论管理界面
    /// </summary>
    [Access("257006")]
    public partial class Comment : WebFactory.PageBase
    {
        private readonly CommentManage _myBll = new CommentManage();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.BC_Path.Items.Add(new ListItem("评论管理", "Comment.aspx"));
                if (Request["ContentId"] != null)
                {
                    this.BC_Path.Items.Add(new ListItem(string.Format("《{0}》评论", Request.QueryString["Title"].Trim()),
                        Request.Url.ToString()));

                    Title = string.Format("《{0}》评论", Request.QueryString["Title"].Trim());
                }
                BindList(1);
            }
        }

        private void BindList(int pageNo)
        {
            this.GV_List.EmptyDataTemplate = GetTemplate(this);


            var pp = new PagingParam
            {
                PageSize = this.PageNavigation1.PageSize,
                PageNo = pageNo
            };
            this.GV_List.DataSource = this._myBll.BindList(Request["ContentId"].ToInt(), false, pp);
            this.GV_List.DataBind();

            this.PageNavigation1.RecordCount = pp.RecordCount;

            if (this.GV_List.Rows.Count < 1)
            {
                this.btnDelete.Enabled = false;
                this.btnPass.Enabled = false;
                this.btnDeleteIP.Enabled = false;
            }
        }

        protected void PageNavigation1_PageChanging(object src, WebControls.PageChangingEventArgs e)
        {
            BindList(e.NewPageIndex);
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            var res = this._myBll.Delete(GetSelectedRow.GetIDs(this.GV_List));
            if (res.Errors.Length == 0)
            {
                MsgBox.Message("删除成功！", this.UpdatePanel1);
                BindList(1);
            }
            else
            {
                MsgBox.Message(res.Errors, this.UpdatePanel1);
            }
        }

        protected void btnPass_Click(object sender, EventArgs e)
        {
            var res = this._myBll.Pass(GetSelectedRow.GetIDs(this.GV_List));

            if (res.Errors.Length == 0)
            {
                MsgBox.Message("审核成功！", this.UpdatePanel1);
                BindList(this.PageNavigation1.PageNo);
            }
            else
            {
                MsgBox.Message(res.Errors, this.UpdatePanel1);
            }
        }


        protected void btnDeleteIP_Click(object sender, EventArgs e)
        {
            var res = this._myBll.DeleteForIP(this.txtIP.Text.Trim());

            if (res.Errors.Length == 0)
            {
                MsgBox.Message("删除成功！", this.UpdatePanel1);
                BindList(1);
            }
            else
            {
                MsgBox.Message(res.Errors, this.UpdatePanel1);
            }
        }
    }
}